package com.bubbles.workspace.sync.entity.source.enhance;


import com.bubbles.engine.data.core.entity.BaseEntity;
import com.bubbles.workspace.sync.entity.source.metadata.SourceTable;
import com.bubbles.workspace.sync.key.source.enhance.SourceEnhanceDorisAnalyzeTableKey;
import jakarta.persistence.*;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.Date;

/**
 * <p>description: 源数据源-增强--DORIS表分析记录 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-20
 */
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true, exclude = {"sourceTable"})
@ToString(callSuper = true, exclude = {"sourceTable"})
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "sync", name = "source_enhance_doris_analyze_table")
@IdClass(SourceEnhanceDorisAnalyzeTableKey.class)
@Comment("源数据源-增强--DORIS表分析记录")
public class SourceEnhanceDorisAnalyzeTable extends BaseEntity {
    
    @Id
    @Comment("系统编码")
    private String sourceSystemCode;
    
    @Id
    @Comment("源数据源-数据库名称")
    private String sourceDatabaseName;
    
    @Id
    @Comment("源数据源-表名称")
    private String sourceTableName;
    
    @Id
    @Comment("源数据源-统计时间")
    private Date sourceStatisticDatetime;
    
    @Comment("自上次 ANALYZE 以来该表的更新行数")
    private Long updateRow;
    
    @Comment("保留列，用于在后续版本中记录该表的查询次数")
    private Integer queryTime;
    
    @Comment("表的行数（可能不反映命令执行时的准确行数）")
    private Long rowCount;
    
    @Column(columnDefinition = "TEXT")
    @Comment("已收集统计信息的列")
    private String columns;
    
    @Comment("统计信息触发的方式")
    private String trigger;
    
    @Comment("是否有新分区首次导入了数据")
    private Boolean newPartition;
    
    @Comment("用户是否手动注入了统计信息")
    private Boolean userInject;
    
    /**
     * 关联关系
     */
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({@JoinColumn(name = "sourceSystemCode", referencedColumnName = "sourceSystemCode", insertable = false, updatable = false), @JoinColumn(name = "sourceDatabaseName", referencedColumnName = "sourceDatabaseName", insertable = false, updatable = false), @JoinColumn(name = "sourceTableName", referencedColumnName = "sourceTableName", insertable = false, updatable = false)})
    private SourceTable sourceTable;
}